/**
* @Author: Crissu
* @Date: 2021/4/14 21:30
# @About: context 包
*/

package chapter_4

import (
	"context"
	"fmt"
)

// 使用 context 包，进行传值处理
func Example_414_04() {
	ProcessRequest("jane", "abc123")
}

func ProcessRequest(userID, authToken string) {
	ctx := context.WithValue(context.Background(), "userID", userID)
	ctx = context.WithValue(ctx, "authToken", authToken)
	HandleResponse(ctx)
}

func HandleResponse(ctx context.Context) {
	fmt.Printf(
		"handling response for %v (%v)",
		ctx.Value("userID"),
		ctx.Value("authToken"),
	)
}
